package com.order.controller.back_end;

import com.order.dao.Item;
import com.order.dao.Order;
import com.order.service.ItemService;
import com.order.service.OrderService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@Scope("prototype")
@AllArgsConstructor
public class OrderWebController {

    private OrderService orderService;
    private ItemService itemService;

    @RequestMapping("/getOrders")
    public String getOrders(){
        Order order =new Order();
        List<Order> orders = orderService.getOrders(order);
        //    规范输出
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("订单如下：\n");
        for (Order o: orders) {
            stringBuilder.append(o.toString()).append("\n");
        }
        log.info(stringBuilder.toString());

        return "操作成功";
    }

    @RequestMapping("/get_item/{oid}")
    public String getItem(@PathVariable("oid") int oid){
        List<Item> items = itemService.selectItem(oid);
        //    规范输出
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("订单如下：\n");
        for (Item  i: items) {
            stringBuilder.append(i.toString()).append("\n");
        }
        log.info(stringBuilder.toString());

        return "操作成功";

    }

}
